'''
Created on 2011-1-4

@author: Administrator
'''


def ip2long(ip):
    """return long value according to ip address"""
    t= ip.split('.')
    #v =long(t[0])*256*256*256+long(t[1])*256*256+long(t[2])*256+long(t[3])
    try:
        v =long(t[0])*16777216+long(t[1])*65536+long(t[2])*256+long(t[3])
        return v
    except ValueError:
        print "value error:  "+str(ip)
    


def ipcmp(ip1,ip2):
    dif=ip2long(ip1)-ip2long(ip2)
    if dif>0:
        return 1
    elif dif < 0 :
        return -1
    else:
        return 0
    

if __name__ == '__main__':
    print ip2long("0.1.0.0")